<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 900px;
            height: 700px;
            border: 1px solid green;
            position: relative;
        }
        ul{
            width: 600px;
            height: 400px;
            border: 2px solid plum;
            margin: auto;
        }
        textarea{
            width: 600px;
            height: 50px;
            margin-top: 10px;
            border: 1px solid purple;
            position: absolute;
            left: 150px;
            
        }
        li{
            list-style: none;
            /* width: 600px; */
            height: 20px;
            background-color: gray;
            padding: 2px;
        }
        button{
            height: 50px;
            width: 150px;
            margin: auto;
            background-color: blueviolet;
            position: absolute;
            left: 300px;
            bottom: 100px;
        }
    </style>
</head>
<body>
    <div>
        <h1 style="text-align: center;">留言板</h1>
        <ul></ul>
        <textarea placeholder="请编辑留言"></textarea>
        <button class="sub">发布</button>
    </div>
    <script>
        const btn=document.querySelector('.sub');
        const text=document.querySelector('textarea');
        const ul=document.querySelector('ul');
        btn.onclick=function(){
            if(text.value==''){
                alert('你没有输入内容呢！');
                return false;
            }else{
                const li=document.createElement('li');
                li.innerHTML=text.value;
                ul.insertBefore(li,ul.children[0]);
                text.value='';
            }
        };

        const button=document.createElement('button');
        button.className='remove';
        button.innerHTML='删除';
        button.onclick=function(){
            ul.removeChild(this.parentNode);
            const li=this.parentNode;
        };
       
    </script>
</body>
</html>